package org.goldfish.mapreduce.wordcount;

import lombok.extern.slf4j.Slf4j;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.util.StringTokenizer;
@Slf4j
public class WordCountMapper extends Mapper
        <Object, Text, Text, IntWritable> {
    private final static IntWritable one = new IntWritable(1);
    private final Text word = new Text();

    public void map(Object key, Text value, Context context)
            throws java.io.IOException, InterruptedException {
        String line = value.toString();
        log.info("map: {}", line);
        StringTokenizer itr = new StringTokenizer(line);
        while (itr.hasMoreTokens()) {
            String nextToken=itr.nextToken();
            log.info("map token: {}", nextToken);
            word.set(nextToken);
            context.write(word, one);
        }
    }
}
